home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 24 April 1997
- //
- // Description:
- // This script provides an option box dialog for the normalConstraint command.
- //
- // Input Arguments:
- // boolean showOptionBox true - show the option box dialog
- // false - just execute the command
- //
- // Procedure Name:
- // setOptionVars
- //
- // Description:
- // Initialize the option values.
- //
- // Input Arguments:
- // Whether to set the options to default values.
- //
- // Return Value:
- // None.
- //
- proc setOptionVars(int $forceFactorySettings)
- {
- // weight
- //
- if ($forceFactorySettings || !`optionVar -exists normalConstraintWeight`) {
- optionVar -floatValue normalConstraintWeight 1.0;
- }
-
- // aimVector.
- //
- if ($forceFactorySettings || !`optionVar -exists normalConstraintAimVector`) {
- optionVar -floatValue normalConstraintAimVector 1.0
- -floatValueAppend normalConstraintAimVector 0.0
- -floatValueAppend normalConstraintAimVector 0.0;
- }
-
- // upVector.
- //
- if ($forceFactorySettings || !`optionVar -exists normalConstraintUpVector`) {
- optionVar -floatValue normalConstraintUpVector 0.0
- -floatValueAppend normalConstraintUpVector 1.0
- -floatValueAppend normalConstraintUpVector 0.0;
- }
-
- // World up
-
- if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpType`) {
- optionVar -stringValue normalConstraintWorldUpType "vector";
- }
-
- if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpVector`) {
- optionVar -floatValue normalConstraintWorldUpVector 0.0
- -floatValueAppend normalConstraintWorldUpVector 1.0
- -floatValueAppend normalConstraintWorldUpVector 0.0;
- }
-
- if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpObject`) {
- optionVar -stringValue normalConstraintWorldUpObject "";
- }
- }
-
- //
- // Procedure Name:
- // normalConstraintSetup
- //
- // Description:
- // Update the state of the option box UI to reflect the option values.
- //
- // Input Arguments:
- // parent - Top level parent layout of the option box UI.
- // Required so that UI object names can be
- // successfully resolved.
- //
- // forceFactorySettings - Whether the option values should be set to
- // default values.
- //
- // Return Value:
- // None.
- //
- global proc normalConstraintSetup(string $parent, int $forceFactorySettings)
- {
- // Retrieve the option settings
- //
- setOptionVars($forceFactorySettings);
-
- setParent $parent;
-
- // Query the optionVar's and set the values into the controls.
-
- // weight
- //
- floatSliderGrp -edit
- -value `optionVar -query normalConstraintWeight`
- normalConstraintWeight;
-
- // aimVector.
- //
- float $aimVector[] = `optionVar -query normalConstraintAimVector`;
- floatFieldGrp -edit
- -value1 $aimVector[0]
- -value2 $aimVector[1]
- -value3 $aimVector[2]
- normalConstraintAimVector;
-
- // upVector.
- //
- float $upVector[] = `optionVar -query normalConstraintUpVector`;
- floatFieldGrp -edit
- -value1 $upVector[0]
- -value2 $upVector[1]
- -value3 $upVector[2]
- normalConstraintUpVector;
-
- // World up
-
- string $worldUpType = `optionVar -query normalConstraintWorldUpType`;
- switch ( $worldUpType )
- {
- case "scene":
- optionMenuGrp -edit -select 1 normalConstraintWorldUpType;
- break;
- case "object":
- optionMenuGrp -edit -select 2 normalConstraintWorldUpType;
- break;
- case "objectrotation":
- optionMenuGrp -edit -select 3 normalConstraintWorldUpType;
- break;
- case "vector":
- optionMenuGrp -edit -select 4 normalConstraintWorldUpType;
- break;
- case "none":
- optionMenuGrp -edit -select 5 normalConstraintWorldUpType;
- break;
- }
-
- float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
- floatFieldGrp -edit
- -value1 $worldUpVector[0]
- -value2 $worldUpVector[1]
- -value3 $worldUpVector[2]
- normalConstraintWorldUpVector;
-
- textFieldGrp -edit
- -text `optionVar -query normalConstraintWorldUpObject`
- normalConstraintWorldUpObject;
-
- normalConstraintEnabling $parent;
- }
-
- //
- // Procedure Name:
- // normalConstraintCallback
- //
- // Description:
- // Update the option values with the current state of the option box UI.
- //
- // Input Arguments:
- // parent - Top level parent layout of the option box UI. Required so
- // that UI object names can be successfully resolved.
- //
- // doIt - Whether the command should execute.
- //
- // Return Value:
- // None.
- //
- global proc normalConstraintCallback(string $parent, int $doIt)
- {
- setParent $parent;
-
- // Set the optionVar's from the control values, and then
- // perform the command.
-
- // weight
- //
- optionVar -floatValue normalConstraintWeight
- `floatSliderGrp -query -value normalConstraintWeight`;
-
- // aimVector.
- //
- optionVar -floatValue normalConstraintAimVector
- `floatFieldGrp -query -value1 normalConstraintAimVector`
- -floatValueAppend normalConstraintAimVector
- `floatFieldGrp -query -value2 normalConstraintAimVector`
- -floatValueAppend normalConstraintAimVector
- `floatFieldGrp -query -value3 normalConstraintAimVector`;
-
- // upVector.
- //
- optionVar -floatValue normalConstraintUpVector
- `floatFieldGrp -query -value1 normalConstraintUpVector`
- -floatValueAppend normalConstraintUpVector
- `floatFieldGrp -query -value2 normalConstraintUpVector`
- -floatValueAppend normalConstraintUpVector
- `floatFieldGrp -query -value3 normalConstraintUpVector`;
-
- // World up
-
- int $state = `optionMenuGrp -query -select normalConstraintWorldUpType`;
- switch ( $state )
- {
- case 1:
- optionVar -stringValue normalConstraintWorldUpType "scene";
- break;
- case 2:
- optionVar -stringValue normalConstraintWorldUpType "object";
- break;
- case 3:
- optionVar -stringValue normalConstraintWorldUpType "objectrotation";
- break;
- case 4:
- optionVar -stringValue normalConstraintWorldUpType "vector";
- break;
- case 5:
- optionVar -stringValue normalConstraintWorldUpType "none";
- break;
- }
-
- optionVar -floatValue normalConstraintWorldUpVector
- `floatFieldGrp -query -value1 normalConstraintWorldUpVector`
- -floatValueAppend normalConstraintWorldUpVector
- `floatFieldGrp -query -value2 normalConstraintWorldUpVector`
- -floatValueAppend normalConstraintWorldUpVector
- `floatFieldGrp -query -value3 normalConstraintWorldUpVector`;
-
- optionVar -stringValue normalConstraintWorldUpObject
- `textFieldGrp -query -text normalConstraintWorldUpObject`;
-
- if ($doIt) {
- performNormalConstraint 0;
- addToRecentCommandQueue "performNormalConstraint 0" "NormalConstraint";
- }
- }
-
- // Callbacks to dim/undim different widget
- //
- global proc normalConstraintEnabling(string $parent)
- {
- setParent $parent;
-
- int $state = `optionMenuGrp -query -select normalConstraintWorldUpType`;
- switch ( $state )
- {
- case 1: // Scene Up
- case 5: // None
- floatFieldGrp -edit -enable false normalConstraintWorldUpVector;
- textFieldGrp -edit -enable false normalConstraintWorldUpObject;
- break;
- case 2: // Object Up
- floatFieldGrp -edit -enable false normalConstraintWorldUpVector;
- textFieldGrp -edit -enable true normalConstraintWorldUpObject;
- break;
- case 3: // Object Rotation Up
- floatFieldGrp -edit -enable true normalConstraintWorldUpVector;
- textFieldGrp -edit -enable true normalConstraintWorldUpObject;
- break;
- case 4: // Vector
- floatFieldGrp -edit -enable true normalConstraintWorldUpVector;
- textFieldGrp -edit -enable false normalConstraintWorldUpObject;
- break;
- }
- }
-
- //
- // Procedure Name:
- // normalConstraintOptions
- //
- // Description:
- // Construct the option box UI. Involves accessing the standard option
- // box and customizing the UI accordingly.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
- proc normalConstraintOptions()
- {
- // Name of the command for this option box.
- //
- string $commandName = "normalConstraint";
-
- // Build the option box actions.
- //
- string $callback = ($commandName + "Callback");
- string $setup = ($commandName + "Setup");
-
- // Get the option box.
- //
- string $layout = getOptionBox();
- setParent $layout;
-
- // Pass the command name to the option box.
- //
- setOptionBoxCommandName($commandName);
-
- // Activate the default UI template.
- //
- setUITemplate -pushTemplate DefaultTemplate;
-
- // Turn on the wait cursor.
- //
- waitCursor -state 1;
-
- string $parent = `columnLayout -adjustableColumn 1`;
-
- floatSliderGrp -label "Weight"
- -field true -min 0.0 -max 10.0
- normalConstraintWeight;
-
- floatFieldGrp -label "Aim Vector"
- -numberOfFields 3
- normalConstraintAimVector;
-
- floatFieldGrp -label "Up Vector"
- -numberOfFields 3
- normalConstraintUpVector;
-
- optionMenuGrp -l "World Up Type"
- -cc ("normalConstraintEnabling " + $parent)
- normalConstraintWorldUpType;
- menuItem -l "Scene Up" normalConstraintUpDirMI1;
- menuItem -l "Object Up" normalConstraintUpDirMI2;
- menuItem -l "Object Rotation Up" normalConstraintUpDirMI3;
- menuItem -l "Vector" normalConstraintUpDirMI4;
- menuItem -l "None" normalConstraintUpDirMI5;
-
- floatFieldGrp -l "World Up Vector" -nf 3 normalConstraintWorldUpVector;
-
- textFieldGrp -l "World Up Object" normalConstraintWorldUpObject;
-
- // Turn off the wait cursor.
- //
- waitCursor -state 0;
-
- // Deactivate the default UI template.
- //
- setUITemplate -popTemplate;
-
- // 'Apply' button.
- //
- string $applyBtn = getOptionBoxApplyBtn();
- button -edit
- -label "Add"
- -command ($callback + " " + $parent + " " + 1)
- $applyBtn;
-
- // 'Save' button.
- //
- string $saveBtn = getOptionBoxSaveBtn();
- button -edit
- -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
- $saveBtn;
-
- // 'Reset' button.
- //
- string $resetBtn = getOptionBoxResetBtn();
- button -edit
- -command ($setup + " " + $parent + " " + 1)
- $resetBtn;
-
- // Set the option box title.
- //
- setOptionBoxTitle("Normal Constraint Options");
-
- // Customize the 'Help' menu item text.
- //
- setOptionBoxHelpTag( "Normal" );
-
- // Set the current values of the option box.
- //
- eval (($setup + " " + $parent + " " + 0));
-
- // Show the option box.
- //
- showOptionBox();
- }
-
- //
- // Procedure Name:
- // normalConstraintHelp
- //
- // Description:
- // Return a short description about this command.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // string.
- //
- proc string normalConstraintHelp()
- {
- // ******** Example
- // " Command: Extrude - create a surface using extrusion.\n" +
- // "Selection: curves and isoparms."
-
- return
- " Command: normalConstraint - Creates a normal constraint.n" +
- "Selection: <A list of things that can be selected>";
- }
-
- //
- // Procedure Name:
- // assembleCmd
- //
- // Description:
- // Construct the command that will apply the option box values.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
- proc string assembleCmd()
- {
- string $cmd = "normalConstraint";
-
- setOptionVars(false);
-
- float $aimVector[] = `optionVar -query normalConstraintAimVector`;
- float $upVector[] = `optionVar -query normalConstraintUpVector`;
-
- $cmd = ($cmd
- + " -weight " + `optionVar -query normalConstraintWeight`
- + " -aimVector "
- + $aimVector[0] + " " + $aimVector[1] + " " + $aimVector[2]
- + " -upVector "
- + $upVector[0] + " " + $upVector[1] + " " + $upVector[2]
- );
-
- // world up related options
-
- string $worldUpType = `optionVar -query normalConstraintWorldUpType`;
- $cmd = ($cmd + " -worldUpType " + "\"" + $worldUpType + "\"" );
- switch ( $worldUpType )
- {
- case "scene":
- case "none":
- break;
- case "object":
- string $worldUpObject = `optionVar -query normalConstraintWorldUpObject`;
- $cmd = ($cmd + " -worldUpObject " + $worldUpObject);
- break;
- case "objectrotation":
- float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
- $cmd = ($cmd + " -worldUpVector "
- + $worldUpVector[0] + " "
- + $worldUpVector[1] + " "
- + $worldUpVector[2]);
- string $worldUpObject = `optionVar -query normalConstraintWorldUpObject`;
- $cmd = ($cmd + " -worldUpObject " + $worldUpObject);
- break;
- case "vector":
- float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
- $cmd = ($cmd + " -worldUpVector "
- + $worldUpVector[0] + " "
- + $worldUpVector[1] + " "
- + $worldUpVector[2]);
- break;
- }
-
- return $cmd;
- }
-
- //
- // Procedure Name:
- // performNormalConstraint
- //
- // Description:
- // Perform the normalConstraint command using the corresponding
- // option values. This procedure will also show the option box
- // window if necessary as well as construct the command string
- // that will invoke the normalConstraint command with the current
- // option box values.
- //
- // Input Arguments:
- // 0 - Execute the command.
- // 1 - Show the option box dialog.
- // 2 - Return the command.
- //
- // Return Value:
- // None.
- //
- global proc string performNormalConstraint(int $action)
- {
- string $cmd = "";
-
- switch ($action) {
-
- // Execute the command.
- //
- case 0:
- // Retrieve the option settings
- //
- setOptionVars(false);
-
- // Get the command.
- //
- $cmd = `assembleCmd`;
-
- // Execute the command with the option settings.
- //
- evalEcho($cmd);
-
- break;
-
- // Show the option box.
- //
- case 1:
- normalConstraintOptions;
- break;
-
- // Return the command string.
- //
- case 2:
- // Retrieve the option settings.
- //
- setOptionVars (false);
-
- // Get the command.
- //
- $cmd = `assembleCmd`;
- break;
- }
- return $cmd;
- }
-
-